<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>ZDH 数据标识组新增</title>
    <meta name="keywords" content="ZDH 数据标识组新增">
    <meta name="description" content="ZDH 数据标识组新增">

    <link rel="shortcut icon" href="img/favicon.ico">

    <link href="css/plugins/chosen/chosen.css" rel="stylesheet">
    <link href="css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css?v=4.1.0" rel="stylesheet">
    <link href="css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link rel="stylesheet" data-name="vs/editor/editor.main" href="js/plugins/vs/editor/editor.main.css">
    <link rel="stylesheet" href="js/plugins/vs/editor/zdh.css">

</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">

    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>数据标识组配置</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="buttons.html#">
                            <i class="fa fa-eye"></i>
                        </a>
                        <ul class="dropdown-menu dropdown-user">
                            <li><a href="javascript:void(0);" onclick="getResourceDesc()">功能说明</a>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="ibox-content">

                    <form id="data_tag_group_add_form" name="data_tag_group_add_form" method="post" class="form-horizontal"
                          action="">

                        <div class="form-group">
                            <label class="col-sm-2 control-label">标识组名称</label>
                            <div class="col-sm-10">
                                <input id="tag_group_name" name="tag_group_name" type="text"
                                       placeholder="标识组名称" class="form-control" aria-required="true"> </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">创建时间</label>
                            <div class="col-sm-10">
                                <input id="create_time" name="create_time" type="text" readonly
                                       placeholder="创建时间" class="form-control" aria-required="true"> </span>
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">标识组code</label>
                            <div class="col-sm-10">
                                <input id="tag_group_code" name="tag_group_code" type="text"
                                       placeholder="标识组code" class="form-control" aria-required="true"> </span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">产品code</label>
                            <div class="col-sm-10">
                                <select id="product_code" name="product_code"
                                        data-placeholder="产品code"
                                        class="chosen-select form-control m-b" tabindex="2">
                                    <option value="">空</option>
                                </select>
                            </div>

                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">标识code</label>
                            <div class="col-sm-10">
                                <select id="tag_codes" name="tag_codes"
                                        data-placeholder="标识code"
                                        class="chosen-select form-control m-b" multiple tabindex="2">
                                    <option value="">空</option>
                                </select>
                            </div>

                        </div>


                        <div class="hr-line-dashed"></div>
                        <!-- 输入数据源结束-->

                        <div class="form-group">
                            <div class="text-center">
                                <button id="save_etl_task" name="save_zdh" class="btn btn-primary"
                                        οnsubmit='return false'
                                        type="button">保存
                                </button>
                                <button id="update_etl_task" name="save_zdh" class="btn btn-primary"
                                        οnsubmit='return false'
                                        type="button">更新
                                </button>
                                <button id="reset" class="btn btn-white" type=reset>清空</button>
                            </div>
                        </div>


                    </form>


                </div>
            </div>


        </div>
    </div>
</div>


<script src="js/zdh_common.js"></script>
<script>
    var require = {
        paths: {
            'vs': 'js/plugins/vs'
        }
    };

</script>
<!-- 全局js -->
<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.6"></script>

<!-- Bootstrap table -->
<script src="js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<!-- 自定义js -->
<script src="js/content.js?v=1.0.0"></script>

<!-- Chosen -->
<script src="js/plugins/chosen/chosen.jquery.js"></script>

<!-- layer javascript -->
<script src="js/plugins/layer/layer.min.js"></script>

<script src="js/plugins/vs/loader.js"></script>
<script src="js/plugins/vs/editor/editor.main.nls.js"></script>
<script src="js/plugins/vs/editor/editor.main.js"></script>
<script type="text/javascript" src="js/plugins/vs/basic-languages/sql/sql.js"></script>

<!-- iCheck -->
<script src="js/plugins/iCheck/icheck.min.js"></script>
<script>
    $(document).ready(function () {
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green',
        });
    });

    (function (document, window, $) {


        (function () {

            var url = location.search; //这一条语句获取了包括问号开始到参数的最后，不包括前面的路径
            var params = url.substr(1);//去掉问号
            var pa = params.split("&");
            var s = new Object();//定义一个全局变量-存储任务ID
            for (var i = 0; i < pa.length; i++) {
                s[pa[i].split("=")[0]] = unescape(pa[i].split("=")[1]);
            }
            $('#product_code').chosen();
            $('#tag_codes').chosen();

            function load_tag_codes(product_code){
                $.ajax({
                    url: server_context+"/data_tag_by_product_code",
                    data: "product_code=" + product_code,
                    type: "post",
                    async: false,
                    dataType: "json",
                    success: function (data) {
                        if(data.code != "200"){
                            layer.msg(data.msg);
                            return ;
                        }
                        var str_tag = '<option value=\"\" hassubinfo=\"true\">空</option>';
                        for (var i = 0; i < data.result.length; i++) {
                            str_tag += '<option value=\"' + data.result[i].tag_code + '\" hassubinfo=\"true\">' + data.result[i].tag_name + '</option>';
                        }
                        $('#tag_codes').html(str_tag);
                        $("#tag_codes").trigger("chosen:updated");
                    },
                    error: function (data) {
                        console.info("error: " + data.responseText);
                    }

                });
            }
            // $("#tag_codes").val(data.result.roles.split(","));
            // $("#tag_codes").trigger("chosen:updated");
            $.ajax({
                type: 'POST',
                url: server_context+"/product_tag_list",
                async:false,
                dataType: 'json',
                data: "",
                //成功返回
                success: function (data) {
                    if(data.code != "200"){
                        layer.msg(data.msg);
                        return ;
                    }
                    var str = '<option value=\"\" hassubinfo=\"true\">空</option>';
                    for (var i = 0; i < data.result.length; i++) {
                        str += '<option value=\"' + data.result[i].product_code + '\" hassubinfo=\"true\">' + data.result[i].product_name + '</option>';
                    }
                    $('#product_code').html(str);
                    $("#product_code").trigger("chosen:updated");
                    $('#product_code').chosen().on("change", function (evt, params) {
                        //加载对应产品下的标识
                        load_tag_codes($("#product_code").val())
                    });
                },
                //处理完成
                complete: function () {
                },
                //报错
                error: function (data) {
                }
            });


            //定义特定数据源展示的div
            function fileShow() {
                console.info("fileShow");
            }

            fileShow();
            //s.id=-1 表示新增,否则表示更新
            if (s.id == -1) {
                console.info("新增按钮触发");
                $('#update_etl_task').hide();
                $('#save_etl_task').show();
            } else {

                if (s.is_copy == "true") {
                    console.info("拷贝按钮触发");
                    $('#update_etl_task').hide();
                    $('#save_etl_task').show();
                } else {
                    console.info("更新按钮触发");
                    $('#save_etl_task').hide();
                    $('#update_etl_task').show();
                }

                buildParam()
            }

            function getMyDate(str) {
                var oDate = new Date(str),
                    oYear = oDate.getFullYear(),
                    oMonth = oDate.getMonth() + 1,
                    oDay = oDate.getDate(),
                    oHour = oDate.getHours(),
                    oMin = oDate.getMinutes(),
                    oSen = oDate.getSeconds(),
                    oTime = oYear + '-' + getzf(oMonth) + '-' + getzf(oDay) + " " + getzf(oHour) + ":" + getzf(oMin) + ":" + getzf(oSen);//最后拼接时间
                return oTime;
            };

            //补0操作
            function getzf(num) {
                if (parseInt(num) < 10) {
                    num = '0' + num;
                }
                return num;
            }


            function buildParam() {
                if (s.id != '-1') {
                    console.info("更新按钮触发--开始赋值对应参数");
                    //开始赋值
                    $.ajax({
                        url: server_context+"/data_tag_group_detail",
                        data: "id=" + s.id,
                        type: "post",
                        async: false,
                        dataType: "json",
                        success: function (data) {
                            console.info("success");
                            // layer.alert(JSON.stringify(data[0]))

                            //获取ETL 说明
                            var tag_group_code = data.result.tag_group_code;
                            $("#tag_group_code").val(tag_group_code);

                            var create_time = data.result.create_time;
                            $("#create_time").val(getMyDate(create_time));


                            //初始化输入数据源select 组件
                            var product_code = data.result.product_code;
                            $("#product_code").val(product_code);
                            $("#product_code").trigger("chosen:updated");

                            //获取标识名称
                            var tag_group_name = data.result.tag_group_name;
                            $("#tag_group_name").val(tag_group_name);
                            load_tag_codes(product_code);
                            var tag_codes = data.result.tag_codes;
                            $("#tag_codes").val(tag_codes.split(','));
                            $("#tag_codes").trigger("chosen:updated");
                        },
                        error: function (data) {
                            console.info("error: " + data.responseText);
                        }

                    });
                }
            }

        })();

    })(document, window, jQuery);

    $('#save_etl_task').click(function () {

        if ($('#tag_group_name').val() == '') {
            layer.msg("标签名称不能为空！");
            return;
        }
        if ($('#tag_group_code').val() == '') {
            layer.msg("标签code不能为空！");
            return;
        }


        $.ajax({
            type: 'POST',
            url: server_context+"/data_tag_group_add",
            async: false,
            dataType: 'json',
            data: $("#data_tag_group_add_form").serialize(),
            //发送数据前
            beforeSend: function () {
                // 禁用按钮防止重复提交
                $("#save_etl_task").attr({disabled: "disabled"});
            },
            //成功返回
            success: function (data) {
                $("#save_etl_task").removeAttr('disabled');
                if(data.code != '200'){
                    console.error(data.msg);
                    layer.msg("执行失败");
                    return ;
                }
                layer.msg("执行成功");
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
            },
            //处理完成
            complete: function () {
                $("#save_etl_task").removeAttr('disabled');
                console.info("complete")
            },
            //报错
            error: function (data) {
                $("#save_etl_task").removeAttr('disabled');
                console.info("error: " + data.responseText);
            }
        });

    });


    $('#update_etl_task').click(function () {

        if ($('#tag_group_name').val() == '') {
            layer.msg("标签名称不能为空！");
            return;
        }
        if ($('#tag_group_code').val() == '') {
            layer.msg("标签code不能为空！");
            return;
        }

        var url = location.search; //这一条语句获取了包括问号开始到参数的最后，不包括前面的路径
        var params = url.substr(1);//去掉问号
        var pa = params.split("&");
        var s = new Object();
        for (var i = 0; i < pa.length; i++) {
            s[pa[i].split("=")[0]] = unescape(pa[i].split("=")[1]);
        }


        $.ajax({
            type: 'POST',
            url: server_context+"/data_tag_group_update",
            dataType: 'json',
            async: false,
            data: $("#data_tag_group_add_form").serialize()+ "&" + "id=" + s.id,
            //发送数据前
            beforeSend: function () {
                // 禁用按钮防止重复提交
                $("#update_etl_task").attr({disabled: "disabled"});
            },
            //成功返回
            success: function (data) {
                $("#update_etl_task").removeAttr('disabled');
                if(data.code != '200'){
                    console.error(data.msg);
                    layer.msg("执行失败");
                    return ;
                }
                layer.msg("执行成功");
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
            },
            //处理完成
            complete: function () {
                console.info("complete")
            },
            //报错
            error: function (data) {
                $("#update_etl_task").removeAttr('disabled');
                layer.error(data.responseText);
                console.info("error: " + data.responseText);
            }
        });

    })

</script>

</body>

</html>
